<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="com.lmpop.trade.ti_teambuy.*" %>
<%@page import="java.util.*" %>
<%@page import="com.lmpop.trade.ti_attach.Ti_attachInfo" %>
<%@page import="com.lmpop.frame.util.PageTools" %>
<%@page import="com.lmpop.trade.ts_category.*" %>
<%@page import="com.lmpop.trade.ti_admin.Ti_adminInfo"%>	
<%
	request.setCharacterEncoding("UTF-8");
	Hashtable ti_teambuy = new Hashtable();

	
	String req_title="";
	
	String req_state="",s_class_attr="";
	
	String user_id = "";
	if(session.getAttribute("session_user_id")!=null){
		user_id = session.getAttribute("session_user_id").toString();
		/**暂时注销根据用户过滤数据
		if(!user_id.equals("771TXP806F41785"))
			ti_teambuy.put("user_id",user_id);
			**/
	}
	
	if(request.getParameter("req_title")!=null && !request.getParameter("req_title").equals("")){
		req_title = request.getParameter("req_title");
		ti_teambuy.put("title",req_title);
	}
	  if(request.getParameter("s_class_attr")!=null && !request.getParameter("s_class_attr").equals("") )
   {
     s_class_attr = request.getParameter("s_class_attr").toString();
     ti_teambuy.put("cat_attr",s_class_attr);  
   }
	if(request.getParameter("req_state")!=null && !request.getParameter("req_state").equals("")){
		req_state = request.getParameter("req_state");
		ti_teambuy.put("req_state",req_state);
	}
	
	String teamType = "";
	if(request.getParameter("teamType")!=null && !request.getParameter("teamType").equals("")){
		teamType = request.getParameter("teamType");
		ti_teambuy.put("team_type",teamType);
	}
	String is_freeshipping="",cash_on_delivery="";
	if(request.getParameter("is_freeshipping")!=null && !request.getParameter("is_freeshipping").equals("")){
		is_freeshipping = request.getParameter("is_freeshipping");
		ti_teambuy.put("is_freeshipping",is_freeshipping);
	}
	if(request.getParameter("cash_on_delivery")!=null && !request.getParameter("cash_on_delivery").equals("")){
		cash_on_delivery = request.getParameter("cash_on_delivery");
		ti_teambuy.put("cash_on_delivery",cash_on_delivery);
	}
    Ti_attachInfo  ti_attachInfo = new Ti_attachInfo();
	Ti_teambuyInfo ti_teambuyInfo = new Ti_teambuyInfo();
	String iStart = "0";
	int limit = 10;
	if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");
	List list = ti_teambuyInfo.getListByPage(ti_teambuy,Integer.parseInt(iStart),limit);
	int counter = ti_teambuyInfo.getCountByObj(ti_teambuy);
	String pageString = new PageTools().getGoogleToolsBar(counter,"index.jsp?req_title="+req_title+"&req_state="+req_state+"&teamType="+teamType+"&iStart=",Integer.parseInt(iStart),limit);

	Ts_categoryInfo ts_categoryInfo = new Ts_categoryInfo();
	
	Map catMap  = ts_categoryInfo.getCatClassMap("13");
	String selecttree = ts_categoryInfo.getCategoryTree("000000000000000","13","");
	Ti_adminInfo adminInfo =new Ti_adminInfo();
	
%>
<html>
  <head>
    
    <title>团购管理</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
	<link href="/program/admin/index/css/thickbox.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
	 <script type="text/javascript" src="/js/thickbox.js"></script>
	<script type="text/javascript" src="/js/commen.js"></script>
	<script type="text/javascript" src="index.js"></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ts_categoryInfo.js'></script>   
	
	<script type="text/javascript" src="/program/admin/goods/s_classify.js"></script>
</head>

<body>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td width="90%">
				<h1>团购管理</h1>
			</td>
			<td>
				<a href="addInfo.jsp"><img src="/program/admin/index/images/post.gif" /></a>
			</td>
		</tr>
	</table>

	<table width="100%" align="center" cellpadding="0" cellspacing="0" class="dl_so">
        <tr>
          <td width="9%" align="center"><img src="/program/admin/index/images/ban_01.gif" /></td>
          <td width="91%" align="left">
		  <h4>团购状态</h4>
			<span><b>团购未开始:</b>开始时间未到.</span><br/>
			<span><b>团购进行中未达到团购人数:</b>团购进行中,未达到团购设定的最低人数.</span><br/>
			<span><b>团购已成功可继续购买:</b>团购进行中,达到团购人数,未限制最低购买数量,未达到团购结束时间.</span><br/>
			<span><b>已卖光:</b>团购进行中,达到团购人数,限制最低购买数量,未达到团购结束时间.</span><br/>
			<span><b>团购成功已结束:</b>团购结束时间已到,并达到团购人数.</span><br/>
			<span><b>团购失败已结束:</b>团购结束时间已到,未达到团购人数.</span>
		  </td>
        </tr>
      </table>
	  <br/>
	
	<form action="index.jsp" name="indexForm" method="post">
	  
	<table width="100%" cellpadding="0" cellspacing="0" class="dl_su">
		<tr>
			<td align="left" >
				
					标题:<input name="req_title" type="text" />&nbsp;
					分类:
				    <select name="sort1" id="sort1" onclick="setSecondClass(this.value);" >
							  <option value="">请选择</option>
					  </select>	
						<select name="sort2" id="sort2" onclick="setTherdClass(this.value);">
							  <option value="">请选择</option>
						</select>		
						<select name="sort3" id="sort3">
							  <option value="">请选择</option>
						</select>
					  <input type="hidden" name="s_class_attr" id="s_class_attr" value=""/>		
						团购类型:
					<select name="teamType" id="teamType">
						<option value="">请选择</option>
						<%=selecttree%>
				   </select>
					
					  <br/>
				团购状态:
					<select name="req_state" id="req_state">
						<option value="">请选择</option>
						<option value="1">团购未开始</option>
						<option value="2">团购进行中未达到团购人数</option>
						<option value="3">团购已成功可继续购买</option>
						<option value="4">已卖光</option>
						<option value="5">团购成功已结束</option>
						<option value="6">团购失败已结束</option>
					</select>
				 
				 <!-- 
				   是否免运费:
					<select name="is_freeshipping" id="is_freeshipping">
						<option value="">请选择</option>
						<option value="1">是</option>
						<option value="0">否</option>
				   </select>
				   货到付款:
					<select name="cash_on_delivery" id="cash_on_delivery">
						<option value="">请选择</option>
						<option value="1">是</option>
						<option value="0">否</option>
				   </select>
				 
				  -->
				<input name="searchInfo" type="button" value="搜索" class="buttab" onclick="return search();"/>	
			</td>
		</tr>
	</table>

	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
		<tr><td><%=pageString %></td></tr>
	</table>
	
	<% 
		int listsize = 0;
		if(list!=null && list.size()>0){
			listsize = list.size();
	%>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
		<tr>
			<td width="90%">
				<input type="button" name="delInfo" onclick="delIndexInfo()" value="删除" class="buttab"/>
			</td>
			<td>
				总计:<%=counter %>条
			</td>
		</tr>
	</table>
	
	<table width="100%" cellpadding="1" cellspacing="1" class="listtab" border="0">
		<tr>
			<th width="5%" align="center"><input type="checkbox" name="checkall" id="checkall" onclick="selectAll()"></th>
			<th>图片</th>
		  	<th width="30%">标题</th>
			
            <!--th >团购类型</th-->
 			
		  	
		  	<th>开始时间</th>
		  	<th>结束时间</th>
		  	
			<th width="10%">修改</th>
	  		<th width="10%">删除</th>
		</tr>
		
		
		<% 
				Map cat_Map = ts_categoryInfo.getCatClassMap("2");
		  		for(int i=0;i<list.size();i++){
		  			Hashtable map = (Hashtable)list.get(i);
		  			String info_id="",cat_attr="",user_name="",cur_store="",group_num="",info_state="",title="",type="",team_type="",price="",old_price="",start_date="",end_date="",team_num="",limit_num="",down_num="",tip="",highlight="",content="",seller="",contact="",buy_limit="",in_date="";
		  			  	if(map.get("info_id")!=null) info_id = map.get("info_id").toString();
		  			  	if(map.get("cat_attr")!=null) cat_attr = map.get("cat_attr").toString();
		  			  	if(map.get("cur_store")!=null) cur_store = map.get("cur_store").toString();
		  			  	if(map.get("group_num")!=null) group_num = map.get("group_num").toString();
						if(map.get("title")!=null) title = map.get("title").toString();
						if(title.length()>40) title=title.substring(0,40);
						if(map.get("type")!=null) type = map.get("type").toString();
						if(map.get("team_type")!=null) team_type = map.get("team_type").toString();
						if(map.get("price")!=null) price = map.get("price").toString();
						if(map.get("old_price")!=null) old_price = map.get("old_price").toString();
						if(map.get("start_date")!=null) start_date = map.get("start_date").toString();
						if(start_date.length()>19)start_date=start_date.substring(0,19);
						if(map.get("end_date")!=null) end_date = map.get("end_date").toString();
						if(end_date.length()>19)end_date=end_date.substring(0,19);
						if(map.get("team_num")!=null) team_num = map.get("team_num").toString();
						if(map.get("limit_num")!=null) limit_num = map.get("limit_num").toString();
						if(map.get("down_num")!=null) down_num = map.get("down_num").toString();
						if(map.get("tip")!=null) tip = map.get("tip").toString();
						if(map.get("highlight")!=null) highlight = map.get("highlight").toString();
						if(map.get("content")!=null) content = map.get("content").toString();
						if(map.get("seller")!=null) seller = map.get("seller").toString();
						if(map.get("contact")!=null) contact = map.get("contact").toString();
						if(map.get("buy_limit")!=null) buy_limit = map.get("buy_limit").toString();
						if(map.get("user_id")!=null){
							 user_id = map.get("user_id").toString();
							 user_name= adminInfo.getrealNameByPK(user_id);
						}
						if(map.get("in_date")!=null) in_date = map.get("in_date").toString();
						if(in_date.length()>19)in_date=in_date.substring(0,19);
						if(map.get("info_state")!=null) info_state = map.get("info_state").toString();
						if (info_state.equals("0"))
						{
							info_state = "<font style='color:red;'>未审核</font><a href='/doTradeReg.do?bpm_id=0778&info_id="+info_id+"'>【审核】</a>";
						}
					else
						{
							info_state = "<font style='color:green;'>已审核</font>";
						}

						String no_start="",no_get_num="",suc_continue="",sell_out="",suc_end="",faile_end="";
						if(map.get("no_start")!=null) no_start = map.get("no_start").toString();
						if(map.get("no_get_num")!=null) no_get_num = map.get("no_get_num").toString();
						if(map.get("suc_continue")!=null) suc_continue = map.get("suc_continue").toString();
						if(map.get("sell_out")!=null) sell_out = map.get("sell_out").toString();
						if(map.get("suc_end")!=null) suc_end = map.get("suc_end").toString();
						if(map.get("faile_end")!=null) faile_end = map.get("faile_end").toString();
						String team_state="";
						if(no_start.equals("0")) team_state = "团购未开始";
						if(no_get_num.equals("0")) team_state = "团购进行中，未达到团购人数";
						if(suc_continue.equals("0")) team_state = "团购成功,继续购买";
						if(sell_out.equals("0")) team_state = "已卖光";
						if(suc_end.equals("0")) team_state = "团购成功";
						if(faile_end.equals("0")) team_state = "团购失败";

					if(!team_type.equals(""))
					{
						 if(catMap!=null)
						 {
						 	team_type=team_type.replace("|","");
							 if(catMap.get(team_type)!=null)
							 {
								team_type=catMap.get(team_type).toString();                 
							  }                  
						 
						  }                 
					}
 					
 					if (!cat_attr.equals("")) {
									String catIds[] = cat_attr.split("\\|");
										if (cat_Map != null) {
											if (cat_Map.get(catIds[0]) != null) {
												cat_attr=cat_Map.get(catIds[0]).toString();
											}
							
									}
								}	
						String img_path =  ti_attachInfo.getFilePathByAttachrootid(info_id);
							if(img_path.equals(""))
							{
							   img_path ="/program/admin/images/cpwu.gif";            
							}  

		  %>
		
		<tr>
			<td width="5%" align="center"><input type="checkbox" name="checkone<%=i %>" id="checkone<%=i %>" value="<%=info_id %>" /></td>
			<td><img src="<%=img_path%>" border="0" width="85" height="85" /></td>
		  	<td width="40%"><a href="updateInfo.jsp?info_id=<%=info_id %>" style="font-size:14px;font-weight:bold;color:#006633"><%=title%></a>
		  	 
		  	<br>商品分类：<%=cat_attr%>；
		  	<br>购买数量：<%if(group_num!=null&&!"".equals(group_num))out.print(group_num);else out.print("0");%>；
		  	团购人数：<%=team_num%>；团购状态：<%=team_state%>；
		  	<br>当前库存：<%if(cur_store!=null&&!"".equals(cur_store))out.print(cur_store);else out.print("0");%>
		  	<br>当前状态：<%=info_state%>
		  	</td>
			
			<!--td><%=team_type%></td-->
		  	 
		  	
		  	<td><%=start_date%></td>
		  	<td><%=end_date%></td>
			<td width="10%">
			<a href="updateInfo.jsp?info_id=<%=info_id %>"><img src="/program/admin/images/edit.gif" title="修改" /></a>

			<a id="updateThisInfo<%=i %>" href="#" onclick="updateOneInfo('<%=i%>','<%=info_id%>','<%=in_date %>')">生成</a>

			</td>
	  		<td width="10%"><a href="javascript:deleteOneInfo('<%=info_id%>','1562');"><img src="/program/admin/images/delete.gif" title="删除" /></a></td>
		</tr>
		
		  <%
		  		}
		  %>
		
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
		<tr>
			<td width="90%">
				<input type="button" name="delInfo" onclick="delIndexInfo()" value="删除" class="buttab"/>
			</td>
			<td>
				总计:<%=counter %>条
			</td>
		</tr>
	</table>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
		<tr><td><%=pageString %></td></tr>
	</table>
	
	<%
		 }
	%>
	
	  <input type="hidden" name="listsize" id="listsize" value="<%=listsize %>" />
	  <input type="hidden" name="pkid" id="pkid" value="" />
	  <input type="hidden" name="bpm_id" id="bpm_id" value="1562" />
	  </form>
</body>

</html>
